import { Toast } from "vant"
import { request } from "../request"
// 添加地址
const incrementAddressRequest = async address => {
  const res = await request({
    url: '/address/add_address',
    method: 'post',
    data: { address }
  })
  Toast.success('添加成功')
  return res
}
// 获得用户的地址信息
const getAllAddressRequest = async userId => {
  const res = await request({
    url: '/address/get_all_address',
    method: 'post',
    data: {
      userId
    }
  })
  return res.data
}
// 删除某个地址
const deleteAddressRequest = async id => {
  const res = await request({
    url: '/address/delete_address',
    method: 'post',
    data: {
      id
    }
  })
  if (res.status === 200) return Toast.success(res.msg)
}
// 查询某个地址的信息
const get_address = async id => {
  const res = await request({
    url: '/address/get_address',
    method: 'post',
    data: {
      id
    }
  })
  return res
}
// 修改某个地址的信息
const update_address = async address => {
  const res = await request({
    url: '/address/update_address',
    method: 'post',
    data: {
      address
    }
  })
  return Toast.success('修改成功')

}

export {
  incrementAddressRequest,
  getAllAddressRequest,
  deleteAddressRequest,
  get_address,
  update_address
}